package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.sjb.common.component.utils.feign.service.mdd.commonuser.UserRoleRestService;
import com.syni.mdd.sjb.common.datatreaure.service.BmsDxClientRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-06-01
 */
@Service
public class BmsDxClientRoleServiceImpl implements BmsDxClientRoleService {

    @Autowired
    UserRoleRestService userRoleRestService;

    final int ROLE_DIANYUAN = 3;
    final int ROLE_DXSH = 4;
    @Override
    public Boolean isDianyuanRole(Integer userId) {
        RpcResponseVo rpcResponseVo = userRoleRestService.getUserRoleAndUserPermission(userId);
        if(rpcResponseVo.isSuccess()){
            Map<String,Object> resultMap = (Map<String, Object>) rpcResponseVo.getData();
            List<Integer> roleIds = (List<Integer>) resultMap.get("roleIds");
            return roleIds.contains(ROLE_DIANYUAN);
        }
        return false;
    }

    @Override
    public Integer getRoleId(Integer userId) {
        Boolean flag = isDianyuanRole(userId);
        if(flag){
            return ROLE_DIANYUAN;
        }else{
            return ROLE_DXSH;
        }
    }
}
